package com.trt.workflow;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipInputStream;

/**
 * @author 谭仁涛
 * @description 流程部署
 * @date 2022/2/19 12:01
 */
@SpringBootTest
public class Part1_Deployment {

    @Autowired
    private RepositoryService repositoryService;

    //通过bpmn部署流程
    @Test
    public void initDeploymentBPMN() {
        // String filename = "BPMN/Part1_Deployment.bpmn";
        // String pngName = "static/Part1_Deployment.png";
        // String filename = "BPMN/Part4_Task.bpmn";
        // String filename = "BPMN/Part4_Task_claim.bpmn";
        // String filename = "BPMN/Part6_UEL_V1.bpmn";
        // String filename = "BPMN/Part6_UEL_V2.bpmn";
        // String filename = "BPMN/Part6_UEL_V3.bpmn";
        // String filename = "BPMN/Part7_Parallel.bpmn";
        // String filename = "BPMN/Part7_Exclusive.bpmn";
        String filename = "BPMN/Part7_Inclusive.bpmn";
        Deployment deployment = repositoryService.createDeployment()
                .addClasspathResource(filename)
                // .addClasspathResource(pngName) // 部署图片
                //.name("流程部署测试BPMN")
                .name("流程部署测试包含网关")
                .deploy();
        System.out.println(deployment.getName());
    }

    //通过ZIP部署流程
    @Test
    public void initDeploymentZIP() {
        InputStream fileInputStream = this.getClass()
                .getClassLoader()
                .getResourceAsStream("BPMN/Part1_DeploymentV2.zip");
        ZipInputStream zip = new ZipInputStream(fileInputStream);
        Deployment deployment = repositoryService.createDeployment().addZipInputStream(zip)
                .name("流程部署测试zip")
                .deploy();
        System.out.println(deployment.getName());
    }

    //查询流程部署
    @Test
    public void getDeployments() {
        List<org.activiti.engine.repository.Deployment> list = repositoryService.createDeploymentQuery().list();
        for (org.activiti.engine.repository.Deployment deployment : list) {
            System.out.println("Id:" + deployment.getId());
            System.out.println("Name:" + deployment.getName());
            System.out.println("DeploymentTime:" + deployment.getDeploymentTime());
            System.out.println("Key:" + deployment.getKey());
        }
    }















}
